package com.ucombuy.youdiangou.recommend;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ucombuy.youdiangou.dal.RecommendDOMapper;
import com.ucombuy.youdiangou.model.RecommendDO;

/**
 * Created by yaosheng on 2021/12/28.
 */
@Service
public class RecommendService implements Serializable {

    @Autowired
    private RecommendDOMapper recommendDOMapper;

    //召回数据，根据userId召回shopIdList
    public List<Integer> recall(Integer userId){

        RecommendDO recommendDO = recommendDOMapper.selectByPrimaryKey(userId);
        if(recommendDO == null){
            recommendDO = recommendDOMapper.selectByPrimaryKey(userId);
        }

        String[] shopIdArr = recommendDO.getRecommend().split(",");
        List<Integer> shopIdList = new ArrayList<>();
        for(int i = 0;i < shopIdArr.length;i ++) {
            shopIdList.add(Integer.valueOf(shopIdArr[i]));
        }
        return shopIdList;
    }
}
